package com.longxi.tianjintianbao.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.longxi.tianjintianbao.ui.fragment.mian.ContactFragment;
import com.longxi.tianjintianbao.ui.fragment.mian.HomeFragment;
import com.longxi.tianjintianbao.ui.fragment.mian.MeFragment;
import com.longxi.tianjintianbao.ui.fragment.mian.MessageFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DingCuiLin on 2016/8/26.
 */

public class MainPagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> mFragmentList;
    private List<String> mTabNameList;
    private Fragment mCurFragment;

    public MainPagerAdapter(FragmentManager fm) {
        super(fm);
        mFragmentList = new ArrayList<>();
        Fragment f = new MessageFragment();
        Fragment f2 = new HomeFragment();
        Fragment f3 = new ContactFragment();
        Fragment f4 = new MeFragment();
        mFragmentList.add(f);
        mFragmentList.add(f2);
        mFragmentList.add(f3);
        mFragmentList.add(f4);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList != null ? mFragmentList.size() : 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTabNameList.get(position);
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        super.setPrimaryItem(container, position, object);
        mCurFragment = (Fragment) object;
    }

    public Fragment getCurrentFragment() {
        return mCurFragment;
    }
}
